package com.atguigu.boot.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UrlPathHelper;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class RequestController {

    @GetMapping("/goToPage")
    public String goToPage(HttpServletRequest request){
        request.setAttribute("msg","请求成功了。。。");
        return "forward:/success" ;
    }


    /**
     * 复杂参数：
     * Map、Model（map、model里面的数据会被放在request的请求域  request.setAttribute）
     *  1.
     * 、Errors/BindingResult、RedirectAttributes（ 重定向携带数据）、
     * ServletResponse（response）、
     * SessionStatus、UriComponentsBuilder、
     * ServletUriComponentsBuilder
     * @param map
     * @param model
     * @param request
     * @return
     */
    @GetMapping("/params")
    public String testParam(Map<String,Object> map, Model model, ServletRequest request){
        map.put("hello","word");

        model.addAttribute("word","hello11");

        request.setAttribute("hellospring" ,"springboot");

        return "forward:/success" ;
    }


    @RequestMapping("/success")
    @ResponseBody
    public Map test(@RequestAttribute(value = "msg",required = false) String mas,HttpServletRequest request){

        HashMap<String, Object> map = new HashMap<>();

        String msg = (String) request.getAttribute("msg");

        Object hello = request.getAttribute("hello");
        Object word = request.getAttribute("word");
        Object hellospring = request.getAttribute("hellospring");


        map.put("hello",hello);
        map.put("word",word);
        map.put("hellospring",hellospring);

        map.put("An_mas",mas);
        map.put("te_mas",msg);


        return map;

    }









}
